

$(document).ready(function() {

    query();



});


var query=function () {
    $('#dataTable').dataTable({
        "bDeferRender":true,
        "sAjaxDataProp":"data.projectList",
        "sAjaxSource":"http://localhost:8080/project/queryAllProject",
        "sPaginationType": "bs_full", //"bs_normal", "bs_two_button", "bs_four_button", "bs_full"
        "fnPreDrawCallback": function( oSettings ) {
            $('.dataTables_filter input').addClass('form-control input-large').attr('placeholder', 'Search');
            $('.dataTables_length select').addClass('form-control input-small');
        },
        "oLanguage": {
            "sSearch": "",
            "sLengthMenu": "<span>_MENU_ entries</span>"
        },
        "bJQueryUI": false,
        "bAutoWidth": false,
        "sDom": "<'row'<'col-lg-6 col-md-6 col-sm-12 text-center'l><'col-lg-6 col-md-6 col-sm-12 text-center'f>r>t<'row-'<'col-lg-6 col-md-6 col-sm-12'i><'col-lg-6 col-md-6 col-sm-12'p>>",

        "aoColumns": [
            {"mDataProp":"projectId"},
            {"mDataProp":"stuNum"},
            {"mDataProp":"stuName"},
            {"mDataProp":"stuSex",
                "mRender": function(data) {
                    var value = "男";
                    if (data==1){
                        value = "女";
                    }
                    return value;
                }
            },
            {"mDataProp":"academyName"},
            {"mDataProp":"termYear"},
            {"mDataProp":"termNum"},
            {"mDataProp":"projectName"},
            {"mDataProp":"projectContent"},
            {"mDataProp":"projectStartDate"},
            {"mDataProp":"projectEndtDate"},
            {"mDataProp":"projectContactPeople"},
            {"mDataProp":"projectPhonenum"},
            {"mDataProp":"projectPlatform"},
            {"mDataProp":"projectState",
                "mRender": function(data) {
                    var value = "<span id='refuse' class='label label-danger mr10 mb10'>已拒绝</span>";
                    if (data==1){
                        value = "<span id='download' class='label label-success mr10 mb10'>已通过</span>";
                    }if (data==2){
                        value = "<a href='#'><span id='refuse' class='label label-danger mr10 mb10'>拒绝</span></a>"+
                            "<a href='#'><span id='agree' class='label label-yellow mr10 mb10'>通过</span></a>";
                    }
                    return value;
                }
            }
        ],

    })
};



$(document).on('click', '#agree', function() {
    //projectId
    var projectId=$(this).parents("tr").children(0).eq(0).text();
    layer.confirm('确认要通过此申请么？',{
        btn:['确认','取消']
    },function () {
        $.ajax({
            url: "http://localhost:8080/project/updateProjectState",
            type: "GET",
            async: true,
            data: "projectId=" + projectId+"&projectState=1",
            dataType: "json",
            success:function () {
                layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
                layer.msg('操作成功！')
                setTimeout(function () {
                    parent.location.reload()
                },1500);
            },
            error:function () {
                layer.alert("操作失败!");
            }
        });
    })

});

$(document).on('click', '#refuse', function() {
    //projectId
    var projectId=$(this).parents("tr").children(0).eq(0).text();

    layer.confirm('确认要拒绝此申请么？',{
        btn:['确认','取消']
    },function () {
        $.ajax({
            url: "http://localhost:8080/project/updateProjectState",
            type: "GET",
            async: true,
            data: "projectId=" + projectId+"&projectState=0",
            dataType: "json",
            success:function () {
                layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
                layer.msg('操作成功！')
                setTimeout(function () {
                    parent.location.reload()
                },1500);
            },
            error:function () {
                layer.alert("操作失败!");
            }
        });
    })
});
